package com.mac.macjetpackdemo

import android.util.Log
import android.view.View
import android.widget.Checkable

inline fun View.singClick(time: Long = 700, crossinline block: (View) -> Unit) {
    setOnClickListener {
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastClickTime > time || this is Checkable) {
            lastClickTime = currentTime
            block(this)
        } else {
            Log.i("click", "重复的点击--无效")
        }
    }
}

fun View.singClick(onClickListener: View.OnClickListener, time: Long = 700) {
    setOnClickListener {
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastClickTime > time || this is Checkable) {
            lastClickTime = currentTime
            onClickListener.onClick(this)
        } else {
            Log.i("click", "重复的点击--无效")
        }
    }
}

var View.lastClickTime: Long
    get() = tag as? Long ?: 0
    set(value) {
        tag = value
    }